<script setup>
import { getStatistics1API, getStatistics2API } from '@/api/index.js';
import { ref, onMounted } from 'vue'
import CounTo from '@/components/CounTo.vue';
import IndexNavs from '@/components/IndexNavs.vue';
import IndexChart from '@/components/IndexChart.vue';
import IndexCard from '@/components/IndexCard.vue';
onMounted(() => {
  getStatistics1()
  getStatistics2()
})
const panels = ref([])
const getStatistics1 = async () => {
  const res = await getStatistics1API()
  panels.value = res.panels
  // console.log(panels.value);
}
const goods = ref([])
const order = ref([])
const getStatistics2 = async () => {
  const res = await getStatistics2API()
  goods.value = res.goods
  order.value = res.order

}
</script>
<template>
  <div>
    <el-row :gutter="20" v-permission="['getStatistics1,GET']">
      <template v-if="panels.length === 0">
        <el-col :span="6" v-for="i in 4" :key="i">
          <el-skeleton style="width: 100%" animated loading>
            <template #template>
              <el-card shadow="hover" class="border-0">
                <template #header>
                  <div class="flex justify-between">
                    <el-skeleton-item variant="text" style="width: 50%" />

                    <el-skeleton-item variant="text" style="width: 10%" />

                  </div>
                </template>
                <!-- card body -->
                <el-skeleton-item variant="h3" style="width: 80%" />

                <el-divider></el-divider>
                <div class="flex justify-between text-sm text-gray-500">
                  <el-skeleton-item variant="text" style="width: 50%" />
                  <el-skeleton-item variant="text" style="width: 10%" />
                </div>
              </el-card>
            </template>
          </el-skeleton>
        </el-col>
      </template>

      <el-col :span="6" v-for="(item, index) in panels" :key="index">
        <el-card shadow="hover" class="border-0">
          <template #header>
            <div class="flex justify-between">
              <span class="text-sm">{{ item.title }}</span>
              <el-tag :type="item.unitColor || 'info'" effect="plain">
                {{ item.unit }}
              </el-tag>
            </div>
          </template>
          <!-- card body -->
          <span class="text-3xl font-bold text-gray-500">
            <!-- {{ item.value }} -->
            <coun-to :value="item.value"></coun-to>
          </span>
          <el-divider></el-divider>
          <div class="flex justify-between text-sm text-gray-500">
            <span>{{ item.subTitle }}</span>
            <span>{{ item.subValue }}</span>
          </div>
        </el-card>

      </el-col>
    </el-row>
    <index-navs></index-navs>
    <el-row :gutter="20" class="mt-5">
      <el-col :span="12">
        <IndexChart v-permission="['getStatistics3,GET']"></IndexChart>
      </el-col>
      <el-col :span="12" v-permission="['getStatistics2,GET']">
        <IndexCard title="店铺及商品提示" tip="店铺及商品提示" :btns="goods" class="mb-3"></IndexCard>
        <IndexCard title="交易提示" tip="需要立即处理的交易订单" :btns="order"></IndexCard>
      </el-col>

    </el-row>

  </div>
</template>